package com.br.negocio.vo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "condicao_pagamento")
@SequenceGenerator(name = "condicao_pagamento_seq", sequenceName = "condicao_pagamento_cod_condicao_pagamento_seq", allocationSize = 1)
@NamedQueries ({
	@NamedQuery(name = "loadAllCondicaoPagamento", query = "from CondicaoPagamentoVO as cp order by cp.codigo"),
	@NamedQuery(name = "findCondicaoPagamento", query = "from CondicaoPagamentoVO as cp where cp.codigo = :codigo"),
	@NamedQuery(name = "findDuplicatedCondicaoPagamento", query = "from CondicaoPagamentoVO as cp where cp.descricao = :descricao and cp.codigo != :codigo")
})
public class CondicaoPagamentoVO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "cod_condicao_pagamento")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "condicao_pagamento_seq")
	private int codigo;
	
	@Column(name = "descricao", nullable = false, length = 50)
	private String descricao;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "cod_forma_pagamento", nullable = false)
	@Fetch(FetchMode.JOIN)
	private FormaPagamentoVO formaPagamentoVO;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "condicaoPagamentoVO")
	@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	@JoinColumn(name = "cod_condicao_pagamento")
	private List<ParcelaVO> listaParcela;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_criacao", nullable = false)
	private Date dataCriacao;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "data_alteracao", nullable = false)
	private Date dataAlteracao;
	
	public CondicaoPagamentoVO() {
		
	}
	
	public int getCodigo() {
		return this.codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public String getDescricao() {
		return this.descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	
	public FormaPagamentoVO getFormaPagamentoVO() {
		return this.formaPagamentoVO;
	}

	public void setFormaPagamentoVO(FormaPagamentoVO formaPagamentoVO) {
		this.formaPagamentoVO = formaPagamentoVO;
	}

	public List<ParcelaVO> getListaParcela() {
		return this.listaParcela;
	}

	public void setListaParcela(List<ParcelaVO> listaParcela) {
		this.listaParcela = listaParcela;
	}

	public Date getDataCriacao() {
		return this.dataCriacao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public Date getDataAlteracao() {
		return this.dataAlteracao;
	}

	public void setDataAlteracao(Date dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}

}